package com.cinc.mdm.modules.unit.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cinc.mdm.modules.unit.entity.MdmUnit;
import com.cinc.mdm.modules.unit.mapper.MdmUnitMapper;
import com.cinc.mdm.modules.unit.service.IMdmUnitService;
import org.jeecg.common.util.oConvertUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 单位
 * @Author: jeecg-boot
 * @Date:   2021-09-16
 * @Version: V1.0
 */
@Service
public class MdmUnitServiceImpl extends ServiceImpl<MdmUnitMapper, MdmUnit> implements IMdmUnitService {

    @Override
    public String findUnitCodeByName(String unitName) {
        if(oConvertUtils.isEmpty(unitName)){
            return null;
        }
        LambdaQueryWrapper<MdmUnit> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MdmUnit::getUnitName, unitName);
        List<MdmUnit> mdmUnitList = baseMapper.selectList(queryWrapper);

        return oConvertUtils.listIsEmpty(mdmUnitList) ? null : mdmUnitList.get(0).getUnitCode();
    }
}
